package testgrails



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */

//C-1: Customers have email address, password and created date fields (unit test)
//C-2: Email address must be a unique field (integration test)
//C-3: Email address must be of a valid form (@.*) (unit test)
//C-4: Password must be between 6-8 characters (unit test)

@TestFor(Customer)
class CustomerUnitTests {

	def customer
	
	//C-1: Customers have email address, password and created date fields (unit test)
	void testNullable()
	{
	 customer = new Customer()
	 assertFalse customer.validate('emailAddress')	
	 assertFalse customer.validate('password')
	 assertFalse customer.validate('dateCreated')
	}
	
	//TODO: Email Format not working yet
	//C-3: Email address must be of a valid form (@.*) (unit test)
	void testEmailForm()
	{
//	 customer = new Customer( emailAddress: 'bushrat@gmail.com', password: 'password1', dateCreated: new Date(), lastUpdated: new Date() )
//		
//	 customer.emailAddress = 'bushrat@gmailcom' 
//	 assertFalse customer.validate()	
//	 
//	 customer.emailAddress = 'bushratgmailcom';
//	 assertFalse customer.validate()
//	 
//	 customer.emailAddress = 'bushrat@gmail.com'
//	 assertTrue customer.validate()
//	 
//	 customer.emailAddress = 'bushrat1@gmail.com' 
//	 assertTrue customer.validate()
	}
	
	//C-4: Password must be between 6-8 characters (unit test)
	void testPasswordSize()
	{
	 customer = new Customer( password: '12345678')
	 assertTrue customer.validate()
	 
	 customer = new Customer( password: '123456')
	 assertTrue customer.validate()
			
	 customer.password =  '1234'
	 assertFalse customer.validate()
	 
	 customer.password = '123456789'
	 assertFalse customer.validate()

	}
	

}
